# CROSS_COMPILE=arm-linux-gnueabihf-
# CC = $(CROSS_COMPILE)gcc
# CXX = $(CROSS_COMPILE)g++
CC = gcc
CXX = g++

INCLUDES = /opt/ros/melodic/include
INCLUDEFLAGS = $(addprefix -I,$(INCLUDES))

LIBDIR = /opt/ros/melodic/lib
LIBS = -lroscpp -lroscpp_serialization -lrosconsole -lrostime

TARGET = jm_uvc

SRCS = $(wildcard jm_uvc.cpp) \

OBJS = $(patsubst %cpp,%o,$(SRCS))
DEP = $(patsubst %cpp,%d,$(SRCS))


CXXFLAGS = -w -g  -O0 -Wall -ldl -MMD -fPIC -pthread  -ftree-vectorize -std=c++11 -Wl,--unresolved-symbols=ignore-in-shared-libs -O2  
CXXFLAGS +=  $(addprefix -I,$(INCLUDES)) 

LDFLAGS = $(addprefix -L,$(LIBDIR)) $(LIBS)

all : $(TARGET)

$(TARGET) : $(OBJS)
	@$(CXX) $(CXXFLAGS) $(OBJS) -o $(TARGET)  $(LDFLAGS)
	@echo generate $(TARGET) succesful

%.o : %.cpp
	@$(CXX) $(CXXFLAGS)  -c $< -o $@ $(LDFLAGS) 
	@echo CXX $<

-include $(DEP)

%.d : %.cpp
	@set -e; rm -f $@; $(CXX) -MM $< $(INCLUDEFLAGS) > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

.PHONY : clean
clean:
	@-rm -rf $(OBJS) $(TARGET) $(DEP)